package com.ds.client.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.Image;

/**
 * lose connection screen, used to show lose connection messages
 */
public class LoseConnScreen implements Screen{

	Image loseConnImg;
	Image loseBtn;
	private Stage loseConnStage;
	InitGame game;
	
	public LoseConnScreen(InitGame game){
		this.game = game;
	}
	
	@Override
	public void dispose() {
		loseConnStage.clear();
		
	}

	@Override
	public void hide() {
		
	}

	@Override
	public void pause() {
		
	}

	@Override
	public void render(float arg0) {
		Gdx.gl.glClearColor(255, 255, 255, 255);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		loseConnStage.draw();
		
	}

	@Override
	public void resize(int arg0, int arg1) {
		
	}

	@Override
	public void resume() {
		
	}

	@Override
	public void show() {
		loseConnImg = new Image(new TextureAtlas("res/loseConnScreen/loseConn.pack").findRegion("error"));
		loseBtn = new Image(new TextureAtlas("res/loseConnScreen/exitBtn.pack").findRegion("exit_button"));
		setImagePosition(loseBtn, 325, 50);
		loseConnStage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics
				.getHeight(), false);
		// switch to chooseScreen
		loseBtn.setClickListener(new ClickListener() {
			@Override
			public void click(Actor actor, float arg1, float arg2) {
				game.dispose();
				game.setScreen(game.getChooseScreen());
			}
		});
		loseConnStage.addActor(loseConnImg);
		loseConnStage.addActor(loseBtn);
		Gdx.input.setInputProcessor(loseConnStage);
		
	}
	
	public void setImagePosition(Image image, float x, float y) {
		image.x = x;
		image.y = y;
	}

}
